import axios from 'axios';
import i18n from '@/main.js';
import {Dialog} from 'vant';
import MobileDetect from 'mobile-detect';
function checkVersion(_this) {
    if (process.env.NODE_ENV === 'production_app') {
        _this.$axios.get(`${_this.appUrl}app/api/trainee/app-update-json`).then(res => {
            const resData = JSON.parse(res.data.updateJson);
            let appVersion = window.plus.runtime.versionCode; // 当前版本号
            let serverVersion, openUrl, note;
            let userAgent = navigator.userAgent;
            let md = new MobileDetect(userAgent);
            let os = md.os();
            if (os === 'AndroidOS') {
                serverVersion = resData.Android.version; // 服务器版本号
                openUrl = resData.Android.url; // 下载地址
                note = resData.Android.note; // 文字说明
            } else if (os === 'iOS') {
                serverVersion = resData.IOS.version;
                openUrl = resData.IOS.url;
                note = resData.IOS.note;
            }
            if (parseFloat(appVersion) < parseFloat(serverVersion)) {
                Dialog.alert({
                    title: i18n.t('New_version_detected'), // 检测到新版本
                    message: note
                }).then(() => {
                    window.plus.runtime.openURL(openUrl);
                });
            }
        });
    }
}
export default checkVersion;
